#include <learn/painter/painter3d.h>
#include <learn/painter/win_ctx.h>

using namespace xi::painter;
using namespace std;

void init_proc(const Paint_Context *ctx);
void deal_proc(const Paint_Context *ctx);

int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
    Win_Context window(hInstance, nCmdShow, 100, 100, 800, 800, init_proc, deal_proc, L"My Demo");
    return window.message_loop();
}

// 当前路径
#define SOURCE_PATH ROOT_SOURCE_PATH "/src/my/tinyrenderer"

namespace
{

TGA_Color white(255, 255, 255);
TGA_Color black(0, 0, 0);
TGA_Color red(255, 0, 0);
TGA_Color green(0, 255, 0);
TGA_Color blue(0, 0, 255);
TGA_Color yellow(255, 255, 0);
TGA_Color pink(192, 203, 0);

Mesh_Data mesh;
TGA_Image texture;

} // namespace

void init_proc(const Paint_Context *ctx)
{
    // 注意 Paint_Context 初始会转动到顶视图
    mesh.read(SOURCE_PATH "/african_head.obj");
    texture.read_tga_file(SOURCE_PATH "/african_head_diffuse.tga");

    auto aisMesh = std::make_shared<AIS_Mesh>(mesh);
    ctx->context()->add_object(aisMesh);
}

void deal_proc(const Paint_Context *ctx)
{
    auto painter = ctx->painter();
    painter->refresh();

    // painter->draw_object(mesh, texture, ctx->context()->info()->camera);
}
